﻿using System;
using System.Collections.Generic;

namespace RayDen.SceneLab.Controllers
{
    public class ControllerState<TState>
        where TState : class, ICloneable
    {

        protected Stack<TState> states;
        protected TState current;

        public TState CurrentState
        {
            get
            {
                if (current == null)
                {
                    return default(TState);
                }
                return current;
            }
        }

        public ControllerState(TState init)
        {
            states = new Stack<TState>();
            current = init;
            if (init != null)
                states.Push((TState)current.Clone());
        }

        public void Push()
        {
            states.Push((TState)current.Clone());            
        }

        public void Pop()
        {
            current = states.Pop();
        }


        public void Reset(TState bmp)
        {
            states = new Stack<TState>();
            current = bmp;
            states.Push((TState)current.Clone());
        }
    }
}
